<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="format-detection" content="telephone=no" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
		<script src="../../script/mui.min.js"></script>
		<script src="../../script/jquery.min.js"></script>
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/swiper-3.4.2.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/personal.css">
		<link rel="stylesheet" href="../../css/exam.css">
		<title>岗位考试页</title>
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		<style>
			.weui_mask {
				position: fixed;
				z-index: 998;
				top: 0;
				right: 0;
				bottom: 0;
				left: 0;
			}
			.weui_dialog {
				z-index: 999;
			}
			.swiper-wrapper {
				min-height: 400px
			}
			
			.stu-test .mui-btn-primary {
				color: #fff;
				background-color: #FF9900;
				border: 1px solid #FF9900;
				padding-left: 2em;
				padding-right: 2em;
			}
			.questionItemImgDiv {
				height: 12em;
				width: 80%;
				max-height: 14em;
				max-width: 95%;
				margin-left: 13px;
			}
			.xuanzeImgDiv {
				width: 80%;
				height: 8em;
				max-height: 10em;
			}
			.swiper-wrapper {
				min-height: 400px
			}
			.tiankong {
				font-family: inherit;
				border-bottom: 1px solid #000;
				margin: 0 8px;
				text-align: center;
				width: auto;
				/*word-break:break-all*/
			}
			.question_video_div {
				padding: 10px 10px;
				padding-left: 20px;
			}
			.question_video_div	video {
				width: 100%;
				height: 13em;
				background-color: black;
			}
			.question_video_div	img {
				width: 100%;
				height: 10em;
				background-color: black;
			}
			.option_video_div {
				padding: 10px 10px;
				padding-left: 55px;
			}
			.option_video_div	img {
				width: 100%;
				height: 8em;
				background-color: black;
			}
			.option_video_div	video {
				width: 100%;
				height: 12em;
			}
			table {
				border: 1px solid #ccc;
				border-collapse: collapse;
				border-spacing: 0;
			}
			td, th {
				border: 1px solid #ccc;
				padding: 0;
				text-align: center
			}
			p {
				text-indent: 5px !important;
			}
		</style>
	</head>
	<body >
		<div class="stu-test" id="scroll">
			<div class="base_style_color base_title_Immerse" id='BarAppearance' ></div>
			<div class="base_navigation_bar base_style_color base_navigation_item_bar base_title_position" >
				<a class="base_left_item" href="#" onclick="backKey()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
				<span id="title"></span>
			</div>
			<div class="space10 " style="margin-top: 66px"></div>
			<div class="k-con-border qusetion-type " >
				<div class="k-con-part" style="position: static">
					<p class="k-text-center k-c323 k-f12">
						<span class="test-score-detail "> 试卷分数：<span class="k-cred" id="score"></span>分 </span>
						<span class="test-score-detail"> 通过分数：<span class="k-cred" id="passscore"></span>分 </span>
						<span class="test-score-detail"> 考试时间：<span class="k-cred" id="kstime"></span>分 </span>
					</p>
				</div>
			</div>
			<div class="k-con test-m-bottom70 test-analysis" id="question_div">
				<div class="swiper-container">
					<div class="swiper-wrapper" ></div>
				</div>
			</div>
			<div class="k-con1 k-text-center k-fixed-bottom test-bottom1" >
				<div class="k-con-part1" id="sub_div">
					<div class="remainingtime ">
						<span> 倒计时 </span>
						<span id="kaoShiTime" class="k-cred"></span>
					</div>
					<button type="button" class="mui-btn mui-btn-primary" onclick="CheckSubmit()">
						交卷
					</button>
					<div class="test_card_div">
						<a class="base_right_item "style="color: #18B4ED" href="#popover-card">答题卡 </a>
					</div>
				</div>
			</div>
			<div id="popover-card" class="mui-popover test-num-card" style=" width: 97%">
				<div class="mui-scroll-wrapper">
					<div class="mui-scroll" id="scroll-card"></div>
				</div>
			</div>
		</div>
		<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title" id="checkNum"></strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
					<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
		<div id="StartAlert" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title" id="checkNum3"></strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a onclick="startNo()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
					<a onclick="startYes()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
		<div class="weui_dialog_alert" id="closeAlert" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title" id="checkNum2"></strong>
				</div>
				<div class="weui_dialog_ft">
					<a onclick="Cancel()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/swiper-3.4.2.jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/certificationExam.js"></script>
	<script type="text/javascript" src="../../script/attachmentManager.js"></script>
	<script type="text/javascript">
		/*考试结果数组*/
		var daan = new Object();
		/*题目名称数组*/
		var itemNameArr = new Array();
		/*题目id数组*/
		var itemIdArr = new Array();
		/*qid数组*/
		var qidArr = new Array();
		/*点击状态 1：正常，2不正常*/
		var clickNum = "";
		/*考试计划id*/
		var pid = "";
		/*课程id*/
		var cid = "";
		/*章节id*/
		var chapterid = "";
		/*试卷id*/
		var tid = "";
		/*sid*/
		var sid = "";
		/*考试开始时间*/
		var stime = "";
		/*考试密钥*/
		var signature = "";
		/*考核id*/
		var check_id = "";
		/*考核时长*/
		var timeNum = "";
		/*考核编码*/
		var enumber = "";
		/*考核题目长度*/
		var questionLen = "";
		/*考核状态*/
		var kstype = "";
		/*埋点信息*/
		var message;
		/*埋点信息1*/
		var message1;
		//		var sid = "";
		apiready = function() {
			preData()
			scrollUI();
			//开启加载框
			showProgress();
			// 滚动监听
			listenScroll();
			//获取数据
			loadData();
			kebackListen();
		}
		//预加载数据
		function preData() {
			var h = api.winHeight * 0.3;
			$('#popover-card').css('height', h);
			if (api.pageParam.type == 1) {
				$('#title').text('理论考试');
				message = '开始理论考试' + '</br>' + api.pageParam.quarter_name + '认证';
				message1 = '完成理论考试' + '</br>' + api.pageParam.quarter_name + '认证';
			} else if (api.pageParam.type == 2) {
				$('#title').text('技能考试');
				message = '开始技能考试' + '</br>' + api.pageParam.quarter_name + '认证';
				message1 = '完成技能考试' + '</br>' + api.pageParam.quarter_name + '认证';
			}
			SendBehaviorTrajectoriesNotifi_Authentication('0', '认证岗位考试页', '125', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title, message);
		}

		function startYes() {
			$('#StartAlert').hide();
		}

		function startNo() {
			$('#StartAlert').hide();
			api.closeWin({
			});
		}

		//倒计时
		function daojishi() {
			var t = setInterval(function() {
				if (timeNum != null && timeNum != '') {
					if (timeNum > 0) {
						timeNum--;
						var currentTime = sZhuanHms(timeNum);
						x = document.getElementById("kaoShiTime");
						//查找元素
						x.innerHTML = currentTime;
					} else {
						clearTimeout(t);
						api.toast({
							msg : '答题时间已到正在为您交卷'
						});
						DeleteAnswerNullData();
						SubmitData();
					}
				}
			}, 1000);
		}

		function loadData() {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : 52, //集团id
				exam : api.pageParam.exam,
				type : api.pageParam.type,
				cid : api.pageParam.cid,
				quarter_id : api.pageParam.id,
				
//				exam : 2018071072754,
//				type : 1,
//				cid : 3569,
//				quarter_id : api.pageParam.id,
			};
			console.log(JSON.stringify(param));
			cfnetppPOST(url_startexam, param, true, function(data, status) {
				popu(param);
				popu(data);
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						var list = data.data;
						if (list != null && list != "") {
							$('#summary').text(list.ksdata.ename);
							$('#score').text(list.zsorce);
							$('#passscore').text(list.ksdata.efen);
							var kstime = parseInt(list.dtime) / 60;
							$('#kstime').text(kstime);
							if (list.dtime != null && list.dtime != '' && list.dtime > 0) {
								timeNum = parseInt(list.dtime);
							}
							stime = list.stime;
							sid = list.sid;
							signature = list.signature;
							check_id = list.check_id;
							enumber = list.enumber;
							if (list.shitiarr != null && list.shitiarr != '') {
								kstype = 1;
								//								GetHtmlTestList(list.shitiarr);
								//								daojishi();
								var TestData = GetTestData(list.shitiarr);
								questionLen = TestData.length;
								setUpObject(TestData);
								$(".swiper-wrapper").append(SetTestExamUI(TestData));
								InitmySwiper();
								daojishi();
							} else {
								PopupHint2('题目为空');
							}
						} else {
							PopupHint2('题目为空');
						}
					} else if (data.code == 102) {
						PopupHint2('您已经参加过考试，请等待下次考试机会');
					} else {
						api.toast({
							msg : '获取测验题目数据失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '获取测验题目数据失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		function PopupHint2(str) {
			$("#checkNum2").text(str);
			$('#closeAlert').show();
		}

		function Cancel() {
			$('#closeAlert').hide();
			backClick();
		}

		function backClick() {
			SendBehaviorTrajectoriesNotifi_Authentication('1', '认证岗位考试页', '125', api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname, document.title, message);
			api.closeWin({
			});
		}

		// 滚动监听
		function listenScroll() {
			var winHeight = $(window).height();
			$(window).resize(function() {
				var thisHeight = $(this).height();
				if (winHeight - thisHeight > 50) {
					//当软键盘弹出，在这里面操作
					$("#sub_div").css('display', 'none');
				} else {
					$("#sub_div").css('display', 'block');
					//当软键盘收起，在此处操作
				}
			});
		}

		function setUpObject(data) {
			var questions = data;
			for (var i = 0; i < questions.length; i++) {
				var question = questions[i];
				qidArr.push(question.qid);
				//子问题数组
				if (question.qtype == '1' || question.qtype == '3' || question.qtype == '8'|| question.qtype == '5' || question.qtype == '11') {//单选题
					//取出子题目
					daan[question.qid] = new String();
				} else if (question.qtype == '2' || question.qtype == '7' || question.qtype == '9') {//多选题识图题
					//取出子题目
					daan[question.qid] = new Array();
				} else if (question.qtype == '4' || question.qtype == '10'|| question.qtype == '12') {//论述题
					//取出子题目
					daan[question.qid] = new Array();
				}
			}
		}

		function CheckSubmit() {
			DeleteAnswerNullData();
			var daanLen = ObjectCount(daan);
			var strLen = questionLen - daanLen;
			if (strLen > 0) {//题目未答数量大于0
				$("#checkNum").text("您还有" + strLen + "道题未提交,是否确定提交?");
			} else {
				$("#checkNum").text("是否确定提交？");
			}
			$('#offlineAlert').show();
			clickNum = 1;
		}

		//系统返回键监听
		function kebackListen() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				//coding...
				backKey();
			});
		}

		//退出考试提示
		function backKey() {
			if (kstype == 1) {
				$("#checkNum").html("是否确定退出考试页面？<br/>考试只有一次机会，一旦退出计作0分");
			} else {
				$("#checkNum").text("是否确定退出考试?");
			}
			$('#offlineAlert').show();
			clickNum = 2;
		}

		function cleanCancel() {
			$('#offlineAlert').hide();
		}

		//确定
		function cleanConfirm() {
			$('#offlineAlert').hide();
			if (clickNum == 1) {
				DeleteAnswerNullData();
				SubmitData();
			} else if (clickNum == 2) {
				if (kstype == 1) {
					daan = "{}";
					SubmitData();
				} else {
					backClick();
				}
			}
		}

		//去除空题数据
		function DeleteAnswerNullData() {
			//			for (var k = 0; k < qidArr.length; k++) {
			//				if (daan[qidArr[k]] == null || daan[qidArr[k]] == "" || daan[qidArr[k]] == undefined || JSON.stringify(daan[qidArr[k]]) == "{}" || JSON.stringify(daan[qidArr[k]]) == "") {
			//					delete daan[qidArr[k]];
			//				}
			//			}
			for (var k = 0; k < questionLen; k++) {
				GetAnswerData(k);
			}
			for (var k = 0; k < qidArr.length; k++) {
				if ( typeof daan[qidArr[k]] == 'string') {
					if (isEmpty(daan[qidArr[k]])) {
						delete daan[qidArr[k]];
						k = k - 1;
					}
				} else if ( typeof daan[qidArr[k]] == 'object') {
					if (isObjectEmpty(daan[qidArr[k]])) {
						delete daan[qidArr[k]];
						k = k - 1;
					}
				}
			}
		}

		//提交答题数据
		function SubmitData() {
			//获取到最后一题的答案数据，并存进对象中
			api.showProgress({
				style : 'default',
				animationType : 'fade',
				title : '正在提交中..',
				text : '',
				modal : true
			});
			var param = {
				enumber : enumber, //考试编号
				signature : signature, //秘钥
				check_id : check_id, //章节id
				uid : $api.getStorage('cfnetppuid'), //用户id
				jid : 52, //集团id
				stime : stime, //开始答测验时间（时间戳）
				quarter_id : api.pageParam.id,
				vid : api.pageParam.id,
				xuan : daan,
				message : message1
			};
			cfnetppPOST(url_add_Test, param, false, function(data, status) {
				
				hideProgress();
				if (api.pageParam.type == 1) {//理论考试
					SendBusinessOperationsLogNotifi('认证考试页', '125', param, param, '', data, '认证理论考试提交考试接口', '125-01')
				} else if (api.pageParam.type == 2) {//技能考试
					SendBusinessOperationsLogNotifi('认证考试页', '125', param, param, '', data, '认证技能考试提交考试接口', '125-02')
				}
				if (status == 'success') {
					if (data.code == 200) {
						ShowToast('提交成功');
						sendNotifi();
						setTimeout(function() {
							backClick();
						}, 1000);
					} else if (data.code == 108) {
						ShowToast('请勿重复提交');
					} else {
						api.toast({
							msg : '提交失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '提交失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		function sendNotifi() {
			api.sendEvent({
				name : 'RreshCertificationListNotifi'
			});
		}

		//	生成答题卡题号
		function popoverCardNum(questionLen) {
			for (var i = 0; i < questionLen; i++) {
				$("#scroll-card").append('<span class="qusetion-num-normal">' + (i + 1) + '</span>')
			}
		}
	</script>
</html>